/*
 * Device.cpp
 *
 *  Created on: 2011. 3. 15.
 *      Author: JeeHoon
 */
#include "plugin/Device.h"
#include "api/PluginManager.h"
#include "api/PluginResult.h"
#include <FTelephony.h>
#include <FSystem.h>

using namespace Osp::Base;


Device::Device()
{
	isInitInfo = false;
}

Device::~Device()
{
}

result
Device::OnConstruct(PluginManager * pPluginManager, Osp::Base::String pluginName)
{
	result r = E_SUCCESS;
	return r;
}

result
Device::execute(Osp::Base::String action, Osp::Base::String args, Osp::Base::String callbackId)
{
	result r = E_SUCCESS;

	return r;
}

result
Device::setDeviceInfo()
{
	result r = E_SUCCESS;

	if(isInitInfo == false)
	{
		__name = DEVICE_NAME;
		__phonegap = DEVICE_PHONEGAP;
		__platform = DEVICE_PLATFORM;

		if(E_SUCCESS == r)
		{
			r = Osp::System::SystemInfo::GetValue(L"PlatformVersion",__platformVersion);
		}

		if(E_SUCCESS == r)
		{
			Osp::Telephony::SimInfo *pSimInfo = new Osp::Telephony::SimInfo();

			r = pSimInfo->Construct();
			if(IsFailed(r))
			{
				AppLog("Construct fail");
			}

			__uuid = pSimInfo->GetIccId();

			delete pSimInfo;
		}

		if(E_SUCCESS == r)
		{
			isInitInfo = true;
		}
	}

	if(E_SUCCESS == r)
	{
		Osp::Base::String code;
		code = L"DeviceInfo = {platform: '" + __platform + L"', version:'" + __platformVersion + L"', name:'" + __name + L"', gap:'" + __phonegap + L"', uuid:'" + __uuid + L"'}";
		__pPluginManager->evaluateJavascript(code);
	}

	return r;
}


